#include "Emitter.h"
#include "Connector.h"
#include "TestState.h"

//constructor
Emitter::Emitter(){

    emitRate = 1000;  //ms between emits
    emitVector = b2Vec2(0.01,0);  //force and direction of balls
    pos.x = 200;
    pos.y = 200;
    ballSize = 5;   //size of ball emitted
    doomEntity = false;

}

void Emitter::Update(){

    emitTime += clock.restart();

    if(emitTime.asMilliseconds() >= emitRate){
        TestEntity* t = new TestEntity(BALL, sf::Vector2f(pos.x,pos.y), sf::Vector2f(ballSize,0));
        t->impulseMove(emitVector);
        if(doomEntity) t->doomed = true;
        emitTime = emitTime.Zero;
        TestState::EntityList.push_back(t);
    }

}

//change the initial position of the emitted objects
void Emitter::setPosition(b2Vec2 p){
    pos = p;
}

//change the force and direction of the emitted objects
void Emitter::setEmitDirection(b2Vec2 dir){
    emitVector = dir;
}

//change the doom of the emitted Entity
void Emitter::setEmittedDoom(bool doom){
    doomEntity = doom;
}


